<?php
/**
 * Created by swagger_zxd.
 * User: zxd
 * Date: 2017/12/12
 * Time: 16:57
 */

namespace App\Http\Controllers\Auth;


use App\Http\Controllers\Controller;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Session;
use Laravel\Socialite\Facades\Socialite;

class AuthController extends \Illuminate\Routing\Controller
{

    public function redirectToProvider(Request $request)
    {
//        dd(1);
            return Socialite::driver('github')
                ->with(['redirect_uri' => env('GITHUB_CALLBACK_URL' ) . '?redirect=' . $request->input('redirect')])
                ->redirect();
    }

    public function handleProviderCallback(Request $request)
    {

        $user =Socialite::driver('github')->stateless();;
       // $user=Socialite::driver('github');
//        dd($user);
        Session::put('user', $user);

        $redirect = $request->input('redirect');

        if($redirect)
        {
            return redirect($redirect);
        }

        return 'GitHub auth successful. Now navigate to a demo.';
    }

}